package com.buercorp.wangyu.core1.ch12.threads;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * 锁降级 写锁 -》 读锁
 * @author liyiyu
 */
public class ThreadTest16 {
    public static void main(String[] args) {
        // 可重入读写锁对象
        ReentrantReadWriteLock rrw = new ReentrantReadWriteLock();
        ReentrantReadWriteLock.WriteLock write = rrw.writeLock(); // 写锁
        ReentrantReadWriteLock.ReadLock read = rrw.readLock(); // 读锁

        // 锁降级
        // 获取写锁 获取读锁 释放写锁 释放读锁
        write.lock();
        System.out.println("write");

        read.lock();
        System.out.println("read");

//        write.unlock();
//        read.unlock();




    }
}
